package pikes.xml;

import java.io.IOException;

import pikes.core.Printable;

public class XMLFilter {

	public final void apply(Printable content, Appendable target) throws IOException {
		content.print(new FilteredAppendable(target));

	}

}

class FilteredAppendable implements Appendable {

	private Appendable target = null;

	public FilteredAppendable(final Appendable target) {
		super();
		this.target = target;
	}

	public final Appendable append(CharSequence csq) throws IOException {
		return append(csq, 0, csq.length());
	}

	public final Appendable append(char c) throws IOException {
		if (c != ' ') {
			target.append(c);
		}
		return this;
	}

	public final Appendable append(CharSequence csq, int start, int end) throws IOException {
		for (int i = start; i < end; i++) {
			append(csq.charAt(i));
		}
		return this;
	}

}
